#ifndef __UIDLGBUILDER_H__
#define __UIDLGBUILDER_H__

#pragma once
#include <string>



namespace dui {
    typedef wchar_t* (*PFNTranslateWord)(const wchar_t*);
class UIFrameBuilderDelegate
{
public:
    virtual UIWidget* CreateWidget(LPCTSTR pstrClass) = 0;
};

class DUILIB_API UIFrameBuilder
{
public:
    UIFrameBuilder();
    UIWidget* Build(STRINGorID xml, LPCTSTR type = NULL, UIFrameBuilderDelegate* pCallback = NULL,
        UIRenderManager* pManager = NULL, UIWidget* pParent = NULL);
    UIWidget* Build(UIFrameBuilderDelegate* pCallback = NULL, UIRenderManager* pManager = NULL,
        UIWidget* pParent = NULL);

    CMarkup* GetMarkup();

    void GetLastErrorMessage(LPTSTR pstrMessage, SIZE_T cchMax) const;
    void GetLastErrorLocation(LPTSTR pstrSource, SIZE_T cchMax) const;

    void setWordTranslator(PFNTranslateWord translator);
    static void* allocMemory(size_t size);
    static void freeMemory(void* p);
private:
    UIWidget* _Parse(CMarkupNode* parent, UIWidget* pParent = NULL, UIRenderManager* pManager = NULL);

    CMarkup m_xml;
    UIFrameBuilderDelegate* m_pCallback;
    LPCTSTR m_pstrtype;
    PFNTranslateWord m_pfnTranslateWord;
};

} // namespace dui

#endif // __UIDLGBUILDER_H__
